package com.security.system.controller;

import cn.hutool.captcha.LineCaptcha;
import com.security.utils.CaptchaUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("login")
public class LoginController {

    @GetMapping("")
    public String getNewsListHtml(String type, Map<Object,Object> map){
        map.put("type",type);
        return "system/login/login2";
    }

    @GetMapping("captcha")
    public void getCaptcha(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
        LineCaptcha lineCaptcha = CaptchaUtils.PC_Captcha();
        log.info("验证码====="+lineCaptcha.getCode());
        session.setAttribute(CaptchaUtils.CAPTCHA_SESSION_KEY,lineCaptcha.getCode());
        lineCaptcha.write(response.getOutputStream());
    }

}
